<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-Strict.dtd">
<%@taglib prefix="s" uri="/struts-tags"%>
<%@ page
	import="com.onlineMIS.common.Common_util,java.util.Date,java.text.SimpleDateFormat"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=8" />
<title>禧乐仓连锁店管理信息系统</title>
<%@ include file="../../../common/Style.jsp"%>
<script>

var dataGrid ;
$(document).ready(function(){
	parent.$.messager.progress('close'); 
	
	$('#name').textbox('textbox').keydown (function(e){
	    if (event.keyCode == 13){    

	    	searchSupplier();
	 		event.returnValue=false;
	    }
	});
	
	var params = "";

	dataGrid = $('#dataGrid').datagrid({
		url : 'headQSupplierMgmtJSONAction!listSupplierTagData',
		queryParams: params,
		fit : true,
		border : false,
		pagination : true,
		pageSize : 20,
		pageList : [ 20, 30],		
		checkOnSelect : false,
		selectOnCheck : false,
		singleSelect:false,
		nowrap : false,
		rownumbers : true,
		sortName : 'id',
		sortOrder : 'desc',
		rowStyler: function(index,row){
			var style = "";
			if (row.status == 1)
				style += 'color:red;';

			return style;
		},
		columns : [ [ 
		              
		     {
				field : 'name',
				title : '供应商名字',
				width : 150,
				sortable:true,
				order:'desc'
			},{	
				field : 'tags',
				title : '供应商标签',
				width : 170			
			},{						
				field : 'address',
				title : '地址',
				width : 300
		    }, {	
	    	
				field : 'initialAcctBalance',
				title : '期初账目',
				width : 90,
				sortable:true,
				order:'desc'
			}, {	
	    	
				field : 'currentAcctBalance',
				title : '当前账目',
				width : 90,
				sortable:true,
				order:'desc'
			}, {
				field : 'comment',
				title : '备注信息',
				width : 180
			}, {
				field : 'status',
				title : '状态',
				width : 50,
				sortable:true,
				order:'desc',
				formatter: function (value, row, index){
					if (row.status == 0 )
						return "正常";
					else if (row.status == 1)
						return "冻结";
				}
			}, {				
				field : 'action',
				title : '更改',
				width : 70,
				align: 'center',
			formatter : function(value, row, index) {
				var str = '';
				str += $.formatString('<a href="#" onclick="updateSupplier(\'{0}\');"><img border="0" src="{1}" title="更改供应商信息"/></a>', row.id, '<%=request.getContextPath()%>/conf_files/easyUI/themes/icons/update.png');
				return str;
			}
		}]],
		toolbar : '#toolbar',
	});

});



function BSkeyDown(e){

	var ieKey = event.keyCode;
	 
     
	   
} 

document.onkeydown = BSkeyDown; 



function AddSupplier(){
	var params = "";

	$.modalDialog.opener_dataGrid = dataGrid;
	
	$.modalDialog({
		title : "添加/更新客户信息",
		width : 440,
		height : 320,
		modal : false,
		draggable:false,
		href : 'headQSupplierMgmtJSPAction!preEditSupplier',
		
	});
}
function updateSupplier(id){
	var params = "formBean.supplier.id=" + id;
	$.modalDialog({
		title : "添加/更新客户信息",
		width : 440,
		height : 320,
		modal : false,
		draggable:false,
		href : 'headQSupplierMgmtJSPAction!preEditSupplier?' + params,
		
	});
}
function EditSupplier(){
	var rows = dataGrid.datagrid('getSelections');
	if (rows.length == 0){
		parent.$.messager.alert('错误', '请选中一个客户信息再继续操作', 'error');
		return;
	}
	
	var	id = rows[0].id;

	updateSupplier(id);
	

}
function downloadSupplier(){
	document.searchForm.action="headQSupplierMgmtJSPAction!download";
	document.searchForm.submit();
	
}
function searchSupplier(){
	dataGrid.datagrid('load', $.serializeObject($('#searchForm')));
}
function cleanSearch(){
	$('#searchForm input').val('');
	dataGrid.datagrid('load', {});
}
function refresh(){
	dataGrid.datagrid('load', $.serializeObject($('#searchForm')));
}
function insertSupplierTags(){
	
	var rows = dataGrid.datagrid('getSelections');
	var param = "";
	
	if(rows.length>0){
		for(let index=0;index < rows.length; index++){
			param = param+"formBean.ids=" + rows[index].id+"&"			
		}
		var tagId = $("#tagId").val();
		
		if(tagId ==0){
			$.messager.alert('提示','请选择供应商需要添加的标签！');
		}else{
			var params = param+ "formBean.tagId=" + tagId 
			 $.post("headQSupplierMgmtJSONAction!saveBatchSupplierTags?",params, cleanCallBack,"json");
		}
	}  else {
		$.messager.alert('提示','供应商信息为空,请选择要添加的供应商！');
	}
	
}

function clearSupplierTags(){
	var rows = dataGrid.datagrid('getSelections');

	var param = "";
	if(rows.length>0){
		for(let index=0;index < rows.length; index++){
			param = param+"formBean.ids=" + rows[index].id+"&"			
		}
		var tagId = $("#tagId").val();
		if(tagId ==0){
			$.messager.alert('提示','请选择供应商需要删除的标签！');
		}else{
			var params = param+ "formBean.tagId=" + tagId 
			 $.post("headQSupplierMgmtJSONAction!deleteBatchSupplierTags?",params, cleanCallBack,"json");
		}		
	} else {
		$.messager.alert('提示','供应商信息为空,请选择要修改的供应商！');
	}
	
}

function oneKeyInsert(){
	 $.post("headQSupplierMgmtJSONAction!oneKeyBatchInsertSupplieTags?",null, cleanCallBack,"json");
}

function cleanCallBack(data){
	$.messager.alert('提示',data.message);
	
}
function findSupplier(){
	dataGrid.datagrid('load', $.serializeObject($('#searchForm')));
}
</script>
</head>
<body>
	
<div class="easyui-layout" data-options="fit : true,border : false">
	<div data-options="region:'north',border:false" style="height: 95px;">
	<s:form id="searchForm" name="searchForm"
		theme="simple" method="POST">
		<table width="98%" align="center" class="OuterTable">
			<tr>
				<td>
					<table width="100%" border="0">
						<tr>
							<td height="40" colspan="7">
								<div class="errorAndmes">
									<s:actionerror cssStyle="color:red" />
									<s:actionmessage cssStyle="color:blue" />
								</div>
								<table width="100%" border="0">
									<tr class="PBAOuterTableTitale">
										<td height="35" colspan="5">总部供应商信息
										</td>
									</tr>
											<tr height="30">
												<td width="7%" align="center"><strong>供应商姓名:</strong></td>
												<td width="5%" align="center"><input type="text" style="width: 120px"
													class="easyui-textbox"   data-options="prompt:'请输入供应商名称！'"
													name="formBean.supplierName" id="name"
													/></td>
												<td width="7%" align="center"><strong>标签名称:</strong></td>
												<td width="8%" align="center"><s:select size="1" cssClass="easyui-combobox"
														style="width:120px" id="tagId" list="uiBean.tags"
														listKey="id" name="formBean.tagId" listValue="tagName" /></td>
												<td align="left"><a onclick="insertSupplierTags();"
													href="javascript:void(0);" class="easyui-linkbutton"
													data-options="iconCls:'icon-add',plain:true">批量添加标签</a>
													<a onclick="clearSupplierTags();"
													href="javascript:void(0);" class="easyui-linkbutton"
													data-options="iconCls:'icon-no',plain:true">批量清空标签</a></td>
											</tr>

										</table>
							</td>
						</tr>
					</table>
				</td>
			</tr>
		</table>
		</s:form>
	</div>
			<div data-options="region:'center',border:false">
			<table id="dataGrid">
			</table>

			<div id="toolbar" style="display: none;">
				<a onclick="findSupplier();" href="javascript:void(0);"
					class="easyui-linkbutton"
					data-options="iconCls:'icon-search',plain:true">搜索供应商</a> <a
					onclick="AddSupplier();" href="javascript:void(0);"
					class="easyui-linkbutton"
					data-options="plain:true,iconCls:'icon-add'">添加供应商</a> <a
					onclick="downloadSupplier();" href="javascript:void(0);"
					class="easyui-linkbutton"
					data-options="plain:true,iconCls:'icon-print'">导出供应商</a> 
					<!--  
					 <a onclick="oneKeyInsert();" href="javascript:void(0);"
					class="easyui-linkbutton"
					data-options="plain:true,iconCls:'icon-reload'">一键添加禧乐仓标签(临时)</a>-->
					
			</div>
		</div>
</div>	
</body>
</html>